#ifndef __MOTOR_H
#define __MOTOR_H

#ifdef __cplusplus
#extern "C" {
#endif

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "driver/ledc.h"

typedef enum
{
    MOTOR_ACTON_POS,
    MOTOR_ACTON_NEG,
    MOTOR_ACTON_BOTH
} motor_action_t;

typedef struct motor_s motor_t;

/**
 * @brief 振动马达控制结构体
 */
struct motor_s
{
    gpio_num_t     motor_gpio;   // 马达GPIO引脚
    ledc_timer_t   ledc_timer;   // LEDC定时器
    ledc_channel_t ledc_channel; // LEDC通道
    bool           enable_flag;  // 使能状态
    float          duty_rate;    // 占空比
};

extern motor_t motor1;
extern motor_t motor2;
extern motor_t motor3;
extern TaskHandle_t motor_control_task_handle;

esp_err_t hal_motor_init(motor_t *motor);                                          
esp_err_t hal_motor_on(motor_t *motor);                                          
esp_err_t hal_motor_off(motor_t *motor);                                          
esp_err_t hal_motor_duty_rate_set(motor_t *motor, float duty_rate);
esp_err_t app_motor_init(void);

#ifdef __cplusplus
}
#endif

#endif